﻿using JamesZhao.Engine.GameObjects;
using JamesZhao.Engine.Utils;
using SlimDX.DirectInput;
using SlimMath;

namespace JamesZhao.Engine.GameComponents
{
    internal class CameraMovementComponent : GameComponent
    {
        private readonly SystemTime _systemTime = new SystemTime();
        private float _lastSystemTime;

        public CameraMovementComponent(GameObject owner) : base(owner)
        {
            _lastSystemTime = _systemTime.CurrentTimeInTicks;
        }

        public override void Update()
        {
            base.Update();

            float dt = _systemTime.CurrentTimeInTicks - _lastSystemTime;
            _lastSystemTime = _systemTime.CurrentTimeInTicks;
            Vector2 mouseDelta = Input.MouseDelta;
            //Transform.LocalRotation *= Quaternion.RotationYawPitchRoll(mouseDelta.X / 1000, mouseDelta.Y / 1000, 0);
            //var dh = (float) (dt*0.0000002);
            //var dh = 0.0005f;
            float dh = 0.003f*mouseDelta.X;
            float dp = 0.003f*mouseDelta.Y;
            if (Input.GetKey(Key.W))
            {
                Transform.LocalPosition += Transform.Forward*0.1f;
            }
            else if (Input.GetKey(Key.S))
            {
                Transform.LocalPosition -= Transform.Forward*0.1f;
            }
            Transform.LocalRotation *= Quaternion.RotationYawPitchRoll(dh, dp, 0);
            // Transform.LocalPosition += new Vector3(0, 0, 0.01f);
            //Transform.LocalPosition += new Vector3(.001f, 0, 0);
        }
    }
}